package cn.zn.modules.budget.his.entity;

import lombok.Data;
import org.mongodb.morphia.annotations.Entity;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 预算汇总
 *
 * @author zn
 * @email zhunahao@qq.com
 * @date 2020-05-28 18:58:34
 */
@Data
@Entity
@Document(collection = "budget_info_sum")
public class BudgetInfoSum implements Serializable {
    private static final long serialVersionUID = 1L;
    @Field("sum_id")
    private String sumId;
    @Field("dept_code")
    private String deptCode;
    @Field("project_code")
    private String projectCode;
    @Field("cate_code")
    private String cateCode;
    @Field("project_name")
    private String projectName;
    @Field("cate_name")
    private String cateName;
    @Field("dept_name")
    private String deptName;
    @Field("total_money")
    private Double totalMoney;
    @Field("remark")
    private String remark;
    @Field("freezs_money")
    private Double freezsMoney;
    @Field("use_money")
    private Double useMoney;
    @Field("ap")
    private Integer ap;

    /**
     * 可用金额
     *
     * @return
     */
    public Double getAvailableMoney() {
        BigDecimal bd_total = new BigDecimal(this.totalMoney.toString());
        BigDecimal bd_freezs = new BigDecimal(this.freezsMoney == null ? "0" : this.freezsMoney.toString());
        BigDecimal bd_use = new BigDecimal(this.useMoney == null ? "0" : this.useMoney.toString());
        return bd_total.subtract(bd_freezs).subtract(bd_use).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}
